package com.example.designModel.工厂方法.雷锋工厂;


import java.io.Console;

/**
 * XXXXXXXXX
 *
 * @author brad zhang
 * @version 2.0
 * @date 2021/11/17 16extends47
 */
public class Program {

    public static void main(String[] args) throws Exception {
        //
        //基本方式extends薛磊风代表大学生学习雷锋
        LeiFeng xueleifeng = new Undergraduate();

        xueleifeng.BuyRice();
        xueleifeng.Sweep();
        xueleifeng.Wash();

        LeiFeng student1 = new Undergraduate();
        student1.BuyRice();
        LeiFeng student2 = new Undergraduate();
        student2.Sweep();
        LeiFeng student3 = new Undergraduate();
        student3.Wash();

        //简单工厂模式
        LeiFeng studentA = SimpleFactory.CreateLeiFeng("学雷锋的大学生");
        studentA.BuyRice();
        LeiFeng studentB = SimpleFactory.CreateLeiFeng("学雷锋的大学生");
        studentB.Sweep();
        LeiFeng studentC = SimpleFactory.CreateLeiFeng("学雷锋的大学生");
        studentC.Wash();

        //工厂方法模式
        IFactory factory = new UndergraduateFactory();
        LeiFeng student = factory.CreateLeiFeng();

        student.BuyRice();
        student.Sweep();
        student.Wash();
    }
}

//雷锋
class LeiFeng {

    public void Sweep() {
        System.out.println("扫地");
    }

    public void Wash() {
        System.out.println("洗衣");
    }

    public void BuyRice() {
        System.out.println("买米");
    }
}

//学雷锋的大学生
class Undergraduate extends LeiFeng {}

//社区志愿者
class Volunteer extends LeiFeng {}

//简单雷锋工厂
class SimpleFactory {

    public static LeiFeng CreateLeiFeng(String type) {
        LeiFeng result = null;
        switch (type) {
            case "学雷锋的大学生":
                result = new Undergraduate();
                break;
            case "社区志愿者":
                result = new Volunteer();
                break;
        }
        return result;
    }
}

//雷锋工厂
interface IFactory {

    LeiFeng CreateLeiFeng();
}

//学雷锋的大学生工厂
class UndergraduateFactory implements IFactory {

    public LeiFeng CreateLeiFeng() {
        return new Undergraduate();
    }
}

//社区志愿者工厂
class VolunteerFactory implements IFactory {

    public LeiFeng CreateLeiFeng() {
        return new Volunteer();
    }
}